﻿using HPIT_LiuzuPoint.Common;
using HPIT_LiuzuPoint.Entity.DTOModel;
using HPIT_LiuzuPoint.Entity.POCOModel;
using HPIT_LiuzuPoint.Entity.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HPIT_LiuzuPoint.Business
{
    public class StoreService : BaseService<shop>
    {
        /// <summary>
        /// 对前台页面进行分页
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        public OperateResult Stores(ShopViewModel viewModel)
        {
            int rowCount = 0;
            //利用lambda表达式返回一个IQueryable的接口
            var query = PredicateExtensions.True<shop>();

            if (!string.IsNullOrWhiteSpace(viewModel.Name))
                query = query.And(m => m.shopName == viewModel.Name);
            if (!string.IsNullOrWhiteSpace(viewModel.Man))
                query = query.And(m => m.shopMan == viewModel.Man);
            if (!string.IsNullOrWhiteSpace(viewModel.Address))
                query = query.And(m => m.shopAddress == viewModel.Address);


            //调用BaseService封装好的分页方法
            var list = GetPagedList(viewModel.page, viewModel.rows, ref rowCount, query, m => m.shopId, false)
                .Select(a => new SPViewModel()
                {

                    shopId = a.shopId,
                    shopMan = a.shopMan,
                    shopAddress = a.shopAddress,
                    shopName = a.shopName,
                    shopPhone = a.shopPhone,
                    shopType = a.shopType,

                });

            var data = new EasyUIDataGrid() { total = rowCount, rows = list };

            return new OperateResult(ResultSatae.Success, "", data);
        }
    }
}
